package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.user.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/type/{type}")
    public Result getByType(@PathVariable Integer type){
        List<Activity> activities = activityService.getByType(type);
        return Result.success(activities);
    }

    @PutMapping
    public Result update(@RequestBody Activity activity){
        activityService.update(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Activity activities = activityService.getById(id);
        return Result.success(activities);
    }

    @PostMapping
    public Result addActivity(@RequestBody Activity activity){
        activityService.add(activity);
        return Result.success();
    }


    @GetMapping
    public Result list(ActivityDTO dto){

        PageResult<Activity> pageResult = activityService.list(dto);
        return Result.success(pageResult);
    }

    @DeleteMapping("/{id}")
    public Result DeleteById(@PathVariable Integer id){
        activityService.deleteById(id);
        return Result.success();
    }
}
